package com.pionerko.summa;


import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class SummaActivity extends Activity implements OnClickListener{
	Button mButton,mButt;
    /** Called when the activity is first created. */
    
    public static final String fst_item = "fst";
	public static final String snd_item = "snd";
	public static final String result = "result";
	@Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mButton = (Button) findViewById(R.id.run);
        mButt = (Button) findViewById(R.id.inet);
        mButton.setOnClickListener(this);
        mButt.setOnClickListener(this);
    }

    public void onClick(View v)
    {
    	
    	if (v == mButton) {
	    	EditText frsEditor = (EditText)findViewById(R.id.rows_count);
	        EditText scnEditor = (EditText)findViewById(R.id.columns_count);
	        
	
	        ImageView image = (ImageView) findViewById(R.id.image);
	        image.setImageResource(R.drawable.mario1);
	        
	
	        int frst = Integer.parseInt(frsEditor.getText().toString());
	        int scnd = Integer.parseInt(scnEditor.getText().toString());
	        int rslt = frst + scnd;
	        
	        TextView message = (TextView)findViewById(R.id.resultat);
	        message.setText("Resultat - " + rslt);
        }

        else if(v == mButt){
        	   
        	
        	EditText scorEditor = (EditText)findViewById(R.id.Scores_count);
            EditText logEditor = (EditText)findViewById(R.id.Login_count);
            
        	   HttpClient httpclient = new DefaultHttpClient();
               String urla = "http://www.sabit.dax.ru/site/php/setUserScore.php?sign=asjfhdfjhgf&login=";
               urla = urla + logEditor.getText().toString() + "&score=" + scorEditor.getText().toString() + "&gameNum=1";
               HttpPost httppost = new HttpPost(urla);
        	   
        
               try {
                   ResponseHandler<String> responseHandler = new BasicResponseHandler();
                   String response = httpclient.execute(httppost, responseHandler);
                   Log.i("response :", response);
               } catch (ClientProtocolException e) {
                   Log.i("response :", "ERROR 1");
                   e.printStackTrace();
               } catch (IOException e) {
                   Log.i("response :", "ERROR 2: ");
                   e.printStackTrace();
               }
            }


    	    


        

    }
    }
        
    

